/*
 * DictPopupManager.java
 *
 * Created on 2007-7-4, 17:13:27
 *
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.wangdazhuang.swing;

import java.awt.Component;
import java.awt.Font;
import java.awt.Point;
import javax.swing.JToolTip;
import javax.swing.Popup;
import javax.swing.PopupFactory;

/**
 *
 * @author William Chen
 */
public class DictPopupManager {

    static Popup popup;
    static Text last;
    
    public static void show(Text text, Component src) {
        hide();
        last=text;
        JToolTip tooltip = new JToolTip();
        tooltip.setTipText(last.getTranslation());
        tooltip.setFont(new Font("Dialog", 0, 12));
        Point p = src.getLocationOnScreen();
        int x = p.x + text.getX() + last.getWidth();
        int y = p.y + text.getY() + last.getHeight();
        popup = PopupFactory.getSharedInstance().getPopup(src, tooltip, x, y);
        last.setVisible(true);
        popup.show();
    }
    public static void hide(){
        if(popup!=null && last!=null){
            popup.hide();
            last.setVisible(false);
            popup=null;
            last=null;
        }
    }
}
